package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.GetClientEvent;
	import net.optix.ip.model.ModelLocator;
	import net.optix.ip.vo.ClientVO;

	public class GetClientCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:GetClientEvent = GetClientEvent( event );
			
			var delegate:UserDelegate = new UserDelegate();     
			delegate.getClient( this , myEvent.clientID);		
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{
			trace(event.result+"  get client");
			try
			{
				var client:ClientVO	=	ClientVO.purseClient(event.result);
				for(var i:int	=0; i<model.clients.length; i++)
				{
					if(client.clientID == model.clients[i].clientID)
					{
						model.clients[i]	=	client;
					}
				}
			}
			catch(error:Error)
			{
				
			}
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			trace(event.fault);
			model.result	=	"Program error";
			
		}

	}
}